package com.neusoft.ysu.elm99.service.impl;

import com.neusoft.ysu.elm99.entity.CommonResult;
import com.neusoft.ysu.elm99.entity.Dept;
import com.neusoft.ysu.elm99.service.DeptService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

//5
@Service
public class DeptServiceImpl implements DeptService {
    @Override
    public CommonResult findById(int depnum) {
        Dept dept=new Dept();
        CommonResult result=new CommonResult<>(dept);

        return result;
    }

    @Override
    public CommonResult findAll() {
//        模拟从MyBatis中获得数据
        List<Dept> lds =new ArrayList();
        lds.add(new Dept(10,"hhh","秦皇岛"));
        lds.add(new Dept(11,"asdf","保定"));
        lds.add(new Dept());
//        封装数据为CommonResult
        CommonResult result=new CommonResult(lds);

        return result;
    }

    @Override
    public CommonResult delete(int depnum) {
        int i=12+depnum;
        CommonResult result=new CommonResult(i);
        return result;
    }

    @Override
    public CommonResult addDept(Dept dept) {
//        返回当前对象主键的值，就是id值
        dept.setDeptnum(null);//启动MyBatis生成主键列的值
        int i=1;
        dept.setDeptnum(i);
        Integer key=dept.getDeptnum();
        CommonResult result=new CommonResult(key);
        return result;
    }

    @Override
    public CommonResult modDept(Dept dept) {
        int i=2;
//        一般修改操作只有影响记录的行数，不过你也可以放回具体是第几行

        return new CommonResult<>(i);
    }

}
